package com.leetcode.sorts.tree;

/**
 * @Author: WuPeng
 * @Date: 2021/6/10 3:16 下午
 *
 * 530.二叉搜索树的最小绝对差
 */
public class BinarySearchTree_530 {

    private int result = Integer.MAX_VALUE;
    private TreeNode pre;

    public int getMinimumDifference(TreeNode root) {
        traversal(root);
        return result;
    }

    private void traversal(TreeNode curr){
        if (curr == null) return;
        traversal(curr.left);
        if (pre != null)
            result = Math.min(result, curr.val- pre.val);
        pre = curr;
        traversal(curr.right);
    }

}
